package com.ruoyi.DataManage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.DataManage.domain.Category;
import com.ruoyi.DataManage.domain.University;
import com.ruoyi.DataManage.service.ICategoryService;
import com.ruoyi.DataManage.service.IUniversityService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.DataManage.domain.Subject_tree;
import com.ruoyi.DataManage.service.ISubject_treeService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 学科专业统计Controller
 *
 * @author CehnFneg
 * @date 2024-04-22
 */
@RestController
@RequestMapping("/DataManage/subject_tree")
public class Subject_treeController extends BaseController
{
    @Autowired
    private ISubject_treeService subject_treeService;

    @Autowired
    private IUniversityService universityService;

    @Autowired
    private ICategoryService categoryService;

    /**
     * 查询学科专业统计列表
     */
    @PreAuthorize("@ss.hasPermi('DataManage:subject_tree:list')")
    @GetMapping("/list")
    public AjaxResult list(Subject_tree subject_tree)
    {
        List<Subject_tree> list = subject_treeService.selectSubject_treeList(subject_tree);
        return success(list);
    }

    /**
     * 导出学科专业统计列表
     */
    @PreAuthorize("@ss.hasPermi('DataManage:subject_tree:export')")
    @Log(title = "学科专业统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Subject_tree subject_tree)
    {
        List<Subject_tree> list = subject_treeService.selectSubject_treeList(subject_tree);
        ExcelUtil<Subject_tree> util = new ExcelUtil<Subject_tree>(Subject_tree.class);
        util.exportExcel(response, list, "学科专业统计数据");
    }

    /**
     * 获取学科专业统计详细信息
     */
    @PreAuthorize("@ss.hasPermi('DataManage:subject_tree:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(subject_treeService.selectSubject_treeById(id));
    }

    /**
     * 新增学科专业统计
     */
    @PreAuthorize("@ss.hasPermi('DataManage:subject_tree:add')")
    @Log(title = "学科专业统计", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Subject_tree subject_tree)
    {
        return toAjax(subject_treeService.insertSubject_tree(subject_tree));
    }

    /**
     * 修改学科专业统计
     */
    @PreAuthorize("@ss.hasPermi('DataManage:subject_tree:edit')")
    @Log(title = "学科专业统计", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Subject_tree subject_tree)
    {
        return toAjax(subject_treeService.updateSubject_tree(subject_tree));
    }

    /**
     * 删除学科专业统计
     */
    @PreAuthorize("@ss.hasPermi('DataManage:subject_tree:remove')")
    @Log(title = "学科专业统计", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(subject_treeService.deleteSubject_treeByIds(ids));
    }

    @GetMapping("/universitylist")
    public AjaxResult universityList()
    {
        List<University> universityList = universityService.getUniversityList();
        return AjaxResult.success(universityList);
    }

    @GetMapping("/categorylist/{universityId}")
    public AjaxResult categoryList(@PathVariable Long universityId)
    {
        List<Category> categoryList = categoryService.getCategoryList(universityId);
        return AjaxResult.success(categoryList);
    }
}
